//
//  LYSetViewController.m
//  LY
//
//  Created by lanou3g on 15/12/15.
//  Copyright © 2015年 梁媛. All rights reserved.
//

#import "LYSetViewController.h"
#import "LYSetView.h"
#import "LYGeneralSetViewController.h"
#import "LYAboutViewController.h"
#import "YSpersonalConreoller.h"
#import <AVOSCloud/AVOSCloud.h>
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>

typedef enum {
    ENUM_NO_Login = 0,
    ENUM_Login,
    ENUM_SinaWeibologin,
    ENUM_TencentWeibologin
}TYPE_Login;
@interface LYSetViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)LYSetView *LYSV;
@property(nonatomic,strong)NSArray *setArray;

@property (nonatomic,assign) TYPE_Login type;

@end

@implementation LYSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.LYSV = [[LYSetView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.LYSV.setTableView.dataSource = self;
    self.LYSV.setTableView.delegate = self;
    NSMutableArray *arr1 = @[@"通用设置"].mutableCopy;
    NSMutableArray *arr2 = @[@"关于我们"].mutableCopy;
    NSMutableArray *arr3 = @[@"退出账号"].mutableCopy;
    self.setArray = @[arr1,arr2,arr3];
    self.LYSV.setTableView.separatorStyle = NO;
    self.LYSV.backgroundColor = [UIColor whiteColor];
    self.LYSV.setTableView.scrollEnabled = NO;
    [self.view addSubview:self.LYSV];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.setArray.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.setArray[section]count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reused = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reused];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reused];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.setArray[indexPath.section][indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        LYGeneralSetViewController *GSVC = [[LYGeneralSetViewController alloc] init];
        UINavigationController *na1 = [[UINavigationController alloc] initWithRootViewController:GSVC];
        [self.navigationController presentViewController:na1 animated:YES completion:nil];
    }else if (indexPath.section == 1){
        LYAboutViewController *AVC = [[LYAboutViewController alloc] init];
        UINavigationController *na2 = [[UINavigationController alloc] initWithRootViewController:AVC];
        [self.navigationController presentViewController:na2 animated:YES completion:nil];
    }else if (indexPath.section == 2 && indexPath.row == 0){
        NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"login"];
        if (str == NULL || [str isEqualToString:@"nlogin"]) {
            self.type = ENUM_NO_Login;
        }else if([str isEqualToString:@"slogin"]){
            self.type = ENUM_SinaWeibologin;
        }else if ([str isEqualToString:@"tlogin"]){
            self.type = ENUM_TencentWeibologin;
        }else if([str isEqualToString:@"login"]){
            self.type = ENUM_Login;
        }

        switch (self.type) {
            case ENUM_Login:
                [AVUser logOut];
                break;
            case ENUM_TencentWeibologin:
                [ShareSDK cancelAuthorize:SSDKPlatformTypeTencentWeibo];
                break;
            case ENUM_SinaWeibologin:
                [ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];
                break;
            default:{
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"无用户登陆" preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                [alert addAction:action];
                [self presentViewController:alert animated:YES completion:nil];
                break;
            }
        }
         [[NSUserDefaults standardUserDefaults] setObject:@"nlogin" forKey:@"login"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}

@end
